﻿using System;

namespace Gert3D
{
  public struct Box3
  {
    public double Left;
    public double Right;
    public double Top;
    public double Bottom;
    public double Back;
    public double Front;

    public static Box3 Zero = new Box3(0, 0, 0, 0, 0, 0);

    public Box3(double left, double right, double top, double bottom, double back, double front)
    {
      Left = left;
      Right = right;
      Top = top;
      Bottom = bottom;
      Back = back;
      Front = front;
    }

    public double Width()
    {
      return Right - Left;
    }

    public double Height()
    {
      return Top - Bottom;
    }

    public double Depth()
    {
      return Back - Front;
    }

    public Boolean Intersects(Box3 other)
    {
      if (Left > other.Right)
        return false;
      if (Right < other.Left)
        return false;
      if (Bottom > other.Top)
        return false;
      if (Top < other.Bottom)
        return false;
      if (Front > other.Back)
        return false;
      if (Back < other.Front)
        return false;

      return true;

      /*return 
        ((Left >= other.Left && Left <= other.Right) || (Right >= other.Left && Right <= other.Right)) &&
        ((Top >= other.Bottom && Top <= other.Top) || (Bottom >= other.Bottom && Bottom <= other.Top)) &&
        ((Back >= other.Front && Back <= other.Back) || (Front >= other.Front && Front <= other.Back));*/
    }

    public Boolean IsInside(Vector3 point)
    {
      return
        (point.X >= Left && point.X <= Right) &&
        (point.Y >= Bottom && point.Y <= Top) &&
        (point.Z >= Front && point.Z <= Back);
    }

  }
}